#!/usr/bin/env python
# -*- coding:UTF-8 -*-
"""
flyweight.py
享元模式代码原型
"""
import weakref

class Flyweight(object): pass
class FlyweightA(Flyweight): pass
class FlyweightB(Flyweight): pass

class FlyweightFactory(object):
    _flyweights = weakref.WeakValueDictionary(a=FlyweightA, b=FlyweightB)

    def get_flyweight(self, key): return FlyweightFactory._flyweights.get(key)
